package org.sjcx.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Connection;

public class BasePath {
	protected static String[] SoPath = {
		"http://zhannei.baidu.com/cse/search?s=5592277830829141693&entry=1&q="
		};
	

	public static void main(String[] args) {
		boolean connect = false;
		try {
            URL u = new URL(SoPath[0]+"遮天");
            try {
                HttpURLConnection uConnection = (HttpURLConnection) u.openConnection();
                try {
                    uConnection.connect();
                    //状态
                    System.out.println(uConnection.getResponseCode());
                    connect = true;
                    InputStream is = uConnection.getInputStream();
                    BufferedReader br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
                    StringBuilder sb = new StringBuilder();
                    while(br.read() != -1){
                        sb.append(br.readLine()+"\n");
                    }
                    String content = new String(sb);
                    content = new String(content.getBytes("UTF-8"), "ISO-8859-1");
                    System.out.println(content);
                    br.close();
                } catch (Exception e) {
                    connect = false;
                    e.printStackTrace();
                    System.out.println("connect failed");
                }
                 
            } catch (IOException e) {
                System.out.println("build failed");
                e.printStackTrace();
            }
             
        } catch (MalformedURLException e) {
            System.out.println("build url failed");
            e.printStackTrace();
        }
	}
}
